import {createRouter, createWebHistory} from 'vue-router'
import StaffLayout from "@/views/layout/StaffLayout.vue";
import AdminLayout from "@/views/layout/AdminLayout.vue";
import ElderLayout from "@/views/layout/ElderLayout.vue";
import FamilyLayout from "@/views/layout/FamilyLayout.vue";


const router = createRouter({
    history: createWebHistory(),
    routes: getRoutes()
})

function getRoutes() {
    let defaultRoutes = [
        {
            path: '/staff',
            name: 'staff',
            component: StaffLayout,
            redirect: "/staff/index",
            children: [{
                path: "index",
                component: () =>
                    import ('../views/staff/Index.vue')
            }, {
                path: "editCurrentUser",
                component: () =>
                    import ('../views/EditCurrentUser.vue')
            }, {
                path: "editPassword",
                component: () =>
                    import ('../views/EditPassword.vue')
            },
            { path: 'room-list', component: () => import('@/views/staff/RoomList.vue') },
            { path: 'health-record', component: () => import('@/views/staff/HealthRecord.vue') },
            { path: 'checkup-record', component: () => import('@/views/staff/CheckupRecord.vue') },
            { path: 'medication-record', component: () => import('@/views/staff/MedicationRecord.vue') },
            { path: 'visitor-registration', component: () => import('@/views/staff/VisitorRegistration.vue') }
            ]
        },
        {
            path: '/elder',
            name: 'elder',
            component: ElderLayout,
            redirect: "/elder/index",
            children: [{
                path: "index",
                component: () =>
                    import('@/views/elder/Index.vue')
            }, {
                path: "editCurrentUser",
                component: () =>
                    import('../views/EditCurrentUser.vue')
            }, {
                path: "editPassword",
                component: () =>
                    import('../views/EditPassword.vue')
            },
            { path: 'health-record', component: () => import('@/views/elder/HealthRecord.vue') },
            { path: 'checkup-record', component: () => import('@/views/elder/CheckupRecord.vue') },
            { path: 'medication-record', component: () => import('@/views/elder/MedicationRecord.vue') },
            { path: 'checkin-application', component: () => import('@/views/elder/CheckinApplication.vue') },
            { path: 'checkout-application', component: () => import('@/views/elder/CheckoutApplication.vue') },
            { path: 'notifications', component: () => import('@/views/elder/Notifications.vue') },
            { path: '/profile/edit', component: () => import('@/views/elder/ProfileEdit.vue'), meta: { title: '编辑个人信息' } }
            ]
        },
        {
            path: '/family',
            name: 'family',
            component: FamilyLayout,
            redirect: "/family/index",
            children: [{
                path: "index",
                name: "family-index",
                component: () =>
                    import ('../views/family/Index.vue')
            }, {
                path: "editCurrentUser",
                component: () =>
                    import ('../views/EditCurrentUser.vue')
            }, {
                path: "editPassword",
                component: () =>
                    import ('../views/EditPassword.vue')
            },
            { path: 'health-record', component: () => import('@/views/family/HealthRecord.vue') },
            { path: 'checkup-record', component: () => import('@/views/family/CheckupRecord.vue') },
            { path: 'notifications', component: () => import('@/views/family/Notifications.vue') },
            ]
        },
        {
            path: '/admin',
            name: 'admin',
            component: AdminLayout,
            redirect: "/admin/home",
            children: [{
                path: "home",
                name: "admin-home",
                component: () =>
                    import ('../views/admin/Home.vue')
            },
                {
                    path: 'editCurrentUser',
                    name: 'admin-editCurrentUser',
                    component: () =>
                        import ('../views/EditCurrentUser.vue')
                },
                {
                    path: 'editPassword',
                    name: 'admin-editPassword',
                    component: () =>
                        import ('../views/EditPassword.vue')
                },
                {
                    path: 'admin',
                    name: 'Admin',
                    component: () =>
                        import ('../views/admin/AdminManage.vue')
                },
                {
                    path: 'notice',
                    name: 'admin-notice',
                    component: () =>
                        import ('../views/admin/NoticeManage.vue')
                }
                ,
                {
                    path: 'visitor',
                    name: 'admin-visitor',
                    component: () =>
                        import ('../views/admin/VisitorManage.vue')
                }
                ,
                {
                    path: 'medicationRecord',
                    name: 'admin-medicationRecord',
                    component: () =>
                        import ('../views/admin/MedicationRecordManage.vue')
                }
                ,
                {
                    path: 'checkupRecord',
                    name: 'admin-checkupRecord',
                    component: () =>
                        import ('../views/admin/CheckupRecordManage.vue')
                }
                ,
                {
                    path: 'healthRecord',
                    name: 'admin-healthRecord',
                    component: () =>
                        import ('../views/admin/HealthRecordManage.vue')
                }
                ,
                {
                    path: 'checkoutApplication',
                    name: 'admin-checkoutApplication',
                    component: () =>
                        import ('../views/admin/CheckoutApplicationManage.vue')
                }
                ,
                {
                    path: 'checkinApplication',
                    name: 'admin-checkinApplication',
                    component: () =>
                        import ('../views/admin/CheckinApplicationManage.vue')
                }
                ,
                {
                    path: 'family',
                    name: 'admin-family',
                    component: () =>
                        import ('../views/admin/FamilyManage.vue')
                }
                ,
                {
                    path: 'staff',
                    name: 'admin-staff',
                    component: () =>
                        import ('../views/admin/StaffManage.vue')
                }
                ,
                {
                    path: 'room',
                    name: 'admin-room',
                    component: () =>
                        import ('../views/admin/RoomManage.vue')
                }
                ,
                {
                    path: 'building',
                    name: 'admin-building',
                    component: () =>
                        import ('../views/admin/BuildingManage.vue')
                }
                ,
                {
                    path: 'elder',
                    name: 'admin-elder',
                    component: () =>
                        import ('../views/admin/ElderManage.vue')
                }

            ]
        },
        {
            path: "/",
            name: "main",
            component: () =>
                import ('../views/Login.vue')
        },
        {
            path: "/login",
            name: "login",
            component: () =>
                import ('../views/Login.vue')
        }, {
            path: "/register",
            name: "register",
            component: () =>
                import ('../views/Register.vue')
        }, {
            path: "/retrievePassword",
            name: "front-retrievePassword",
            component: () =>
                import ('../views/RetrievePassword.vue')
        }];
    defaultRoutes.push({
        path: '/:pathMatch(.*)*',
        name: 'NotFound',
        meta: {
            name: ''
        },
        component: () => import ('../views/404.vue')
    })
    console.log('getDynamicRoutes', defaultRoutes)
    return defaultRoutes;
}

router.beforeEach((to, from, next) => {
    next();
});
export default router
